<?php
session_start();
$auth = $_SESSION['auth'];
if($auth<90)
{
	echo '<center>Non hai l\'autorizzazione per accedere a questa pagina.<br><br><img src="images/accesso_negato.gif"></center>';
	exit();
}
//connessione al database
include 'connect.php';

$search = $_GET['search'];

if($search == "tipo")
{
	$tipo = $_POST['ricercatipo'];
	$type = $_POST['ricercatipo'];
	$query = mysql_query("select * from contabilita where tipo='$tipo' order by data desc");
}

else if($search == "causale")
{
	$causale = $_POST['causale'];
	$type = $_POST['causale'];
	$query = mysql_query("select * from contabilita where causale like '%$causale%' order by data desc");
}

else if($search == "importo")
{
	$importo = $_POST['importo'];
	$type = $_POST['importo'];
	$query = mysql_query("select * from contabilita where importo='$importo' order by data desc");
}

else if($search == "data")
{
	$giorno = $_POST['giorno'];
	$mese = $_POST['mese'];
	$anno = $_POST['anno'];
	$data = $anno.'-'.$mese.'-'.$giorno;
	$type = $giorno.'-'.$mese.'-'.$anno;
	$query = mysql_query("select * from contabilita where data='$data' order by data desc");
}

?>


<div id="wrapper">
    	<div id="secWrapper">
        	<div id="container" class="clearfix">
            	<div id="mainCol" class="clearfix">
				    
		<h3 id="why">Registro Contabile - Risultati Ricerca per <?php echo $search; ?>: "<?php echo $type; ?>" </h3><br>
                   
		<font size="2">
		
	<table width="90%" border="1" cellpadding="5" cellspacing="0">
		<tr><th style='padding:5px' align='center'>Tipo</th><th style='padding:5px' align='center'>Causale</th><th style='padding:5px' align='center'>Importo</th><th style='padding:5px' align='center'>Data</th><th style='padding:5px' align='center'>Scontrino</th></tr>
		<?php
		while($query2 = mysql_fetch_array($query))
		{
		?>
		<tr>
		<td style='padding:5px' align='center'><?php echo $query2['tipo']; ?></td><td style='padding:5px' align='center'><?php echo $query2['causale']; ?></td><td style='padding:5px' align='center'><?php echo number_format($query2['importo'], 2, ',' , '.'); ?> Euro</td><td style='padding:5px' align='center'><?php echo date("d-m-Y", strtotime($query2['data'])); ?></td><td style='padding:5px' align='center'><?php if($query2['scontrino'] != "") { ?><a href="scontrini/<?php echo $query2['scontrino']; ?>" target="_blank">visualizza</a><?php } ?></td>
		</tr>
		<?php
		}
		?>
		</table>
		<a href="home.php?page=cercaoperazione">Indietro</a>
	
		</font>
                </div>
                